<?php
namespace app\product\model;

use app\product\model\Model;

class Common extends Model{

    /**
     * 获取基础信息列表
     * @param array $getBase 
     * @param array $where 
    */ 
    public function getBase($where=null,$file='*'){ 
        $baselist = Model::name('sys_basics')
            ->field($file)
            ->where($where)
            ->select()
            ->toArray();
        foreach ($baselist as $key => $value) {
            $baselist[$key]['content']=!empty($value['content'])?json_decode($value['content'],true):[];
        }
        return $baselist;
    }

    /**
     * 获取基础信息
     * @param array $getBaseinfo 
     * @param array $where 
    */ 
    public function getBaseinfo($where=null,$file='*'){ 
        $baseinfo = Model::name('sys_basics')
            ->field($file)
            ->where($where)
            ->find();
        $baseinfo['content']=!empty($baseinfo['content'])?json_decode($baseinfo['content'],true):[];
        return $baseinfo;
    }

    /**
     * 類別列表選擇
     * @param array $getProCate 
     * @param array $where 
    */ 
    public function getProCate($where=null,$file='*'){ 
        $machinecate = Model::name('pro_category')
            ->field($file)
            ->where($where)
            ->select()
            ->toArray();
        return $machinecate;
    }

    /**
     * 獲取類別信息
     * @param array $getProCateinfo 
     * @param array $where 
    */ 
    public function getProCateinfo($where=null,$file='*'){ 
        $machinecate = Model::name('pro_category')
            ->field($file)
            ->where($where)
            ->find();
        return $machinecate;
    }

    /**
     * 当冲产品列表選擇
     * @param array $getDay 
     * @param array $where 
    */ 
    public function getDay($where=null,$file='*'){ 
        $product = Model::name('pro_daytrade')
            ->field($file)
            ->where($where)
            ->select()
            ->toArray();
        return $product;
    }

    /**
     * 当冲产品信息
     * @param array $getDayinfo 
     * @param array $where 
    */ 
    public function getDayinfo($where=null,$file='*'){ 
        $product = Model::name('pro_daytrade')
            ->field($file)
            ->where($where)
            ->find();
        return $product;
    }

    /**
     * 盈利率产品列表選擇
     * @param array $getZero 
     * @param array $where 
    */ 
    public function getZero($where=null,$file='*'){ 
        $product = Model::name('pro_zerorate')
            ->field($file)
            ->where($where)
            ->select()
            ->toArray();
        return $product;
    }

    /**
     * 盈利率产品
     * @param array $getZeroinfo 
     * @param array $where 
    */ 
    public function getZeroinfo($where=null,$file='*'){ 
        $product = Model::name('pro_zerorate')
            ->field($file)
            ->where($where)
            ->find();
        return $product;
    }

    /**
     * 期指产品列表選擇
     * @param array $getTrade 
     * @param array $where 
    */ 
    public function getTrade($where=null,$file='*'){ 
        $product = Model::name('pro_trade')
            ->field($file)
            ->where($where)
            ->select()
            ->toArray();
        return $product;
    }

    /**
     * 期指产品類別信息
     * @param array $getTradeinfo 
     * @param array $where 
    */ 
    public function getTradeinfo($where=null,$file='*'){ 
        $product = Model::name('pro_trade')
            ->field($file)
            ->where($where)
            ->find();
        return $product;
    }
    
    /**
     * 获取基础语言列表
     * @param array $getBase 
     * @param array $where 
    */ 
    public function getLang(){ 
        $lang=[];
        $langs=[
            'list'=>[],
            'total'=>0
        ];
        $lang = Model::name('sys_basics')
            ->field('content,notes')
            ->where('keyname="lang"')
            ->find();
        if(!empty($lang['content'])){
            $lang['notes'] = json_decode($lang['notes'],true);
            $lang['content'] = json_decode($lang['content'],true);
            foreach ($lang['content'] as $key => $value) {
                $langs['list'][$key]['value']=$value;
                $langs['list'][$key]['name']=$lang['notes'][$key];
            }
            unset($lang['content'],$lang['notes']);
        }else{
            $langs['list']=config('langs');
        }
        $langs['total']=count($langs['list']);
        return $langs;
    }

    /**
     * 角色列表
     * @param array $getrole
     * @param array $where 
     */
    public function getrole($where='dels<1',$file='*')
    {
        //部门数据
        $identlist = Model::name('sys_role')
            ->field($file)
            ->where($where)
            ->order('id asc')
            ->select();
        return $identlist;
    }

    /**
     * 账户列表
     * @param array $checkuser
     * @param array $where
     */
    public function checkuser($where = '', $page = 1, $page_size = 10)
    {
        //数据
        $user['datalist'] = Model::name('user_account')
            ->alias('a')
            ->join('sys_role b', 'a.roletype=b.id', 'left')
            ->field(' a.*, b.title as type')
            ->where($where)
            ->limit(($page - 1) * $page_size, $page_size)
            ->order('a.aid desc')
            ->select()
            ->toArray();
        //数据总数
        $user['total'] = Model::name('user_account')
            ->alias('a')
            ->where($where)
            ->count('a.aid');
        return $user;
    }

    /**
     * 账户列表
     * @param array $getuser
     * @param array $where
     */
    public function getuser($where = '', $field='*')
    {
        //数据
        $user = Model::name('user_account')
            ->field($field)
            ->where($where)
            ->find();
        return $user;
    }

    /**
     * 获取对决控制条目
     * @param array $checkuser
     * @param array $where
     */
    public function getDuelcontrol($where = '', $file='a.*')
    {
        //数据
        $datalist = Model::name('pro_dueloperate')
            ->alias('a')
            ->join('pro_dueltrade b', 'a.proid=b.id', 'left')
            ->field($file)
            ->where($where)
            ->select()
            ->toArray();
        return $datalist;
    }


}